Conversation
| import java.util.Arrays; | ||
|
|
||
| public class ContainerImpl implements Container { | ||
| private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8; |
| private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8; | ||
|
|
||
| private int size; | ||
| transient int[] elementData; |
There was a problem hiding this comment.
Why transient? Are you going to serialize container?
| // TODO: please implement me | ||
| // clear to let GC do its work | ||
| for (int i = 0; i < size; i++) | ||
| elementData[i] = 0; |
There was a problem hiding this comment.
Please explain, why do you need it.
There was a problem hiding this comment.
Any explanation why are you setting zero instead of removed elements?
| @Override | ||
| public boolean remove(int index) { | ||
| // TODO: please implement me | ||
| for (int i = 0; i < size; i++) |
| grow(minCapacity); | ||
| } | ||
|
|
||
| private void grow(int minCapacity) { |
There was a problem hiding this comment.
It's a hard to understand what you are doing here. Please add comments.
By the way, looks like copy-paste, so not sure you are aware what is going on.
|
|
||
| if (firstChar == "-".charAt(0)) { | ||
| negative = -1; | ||
| } else if (firstChar == "+".charAt(0)) { |
There was a problem hiding this comment.
Empty condition looks strange.
| //TODO: implement me | ||
| if (value.length != 0 && value != null) { | ||
| char firstChar = value[0]; | ||
| int negative = 1; |
There was a problem hiding this comment.
Not sure it's a good name. It's look weird to init variable named negative with positive integer.
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { |
There was a problem hiding this comment.
Do you remember equals+hashCode contract?
If objects are equal - hash code should be the same.
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { |
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { |
| if (minCapacity - MAX_ARRAY_SIZE > 0) { | ||
| minCapacity = hugeCapacity(minCapacity); | ||
| } | ||
| elementData = Arrays.copyOf(elementData, minCapacity); |
There was a problem hiding this comment.
For sure it's not a good idea to increase array size by 1 each time new element is added.
Please use some multiplier.
| // TODO: please implement me | ||
| // clear to let GC do its work | ||
| for (int i = 0; i < size; i++) | ||
| elementData[i] = 0; |
There was a problem hiding this comment.
Any explanation why are you setting zero instead of removed elements?
| //TODO: implement me | ||
| int i; | ||
| if (value > 1) { | ||
| for (i = 2; i <= value / 2; i++) { |
There was a problem hiding this comment.
I do not say you to put 6, I've just shown you that amount of checks can be significantly decreased.
Please analyse it one more time.
No description provided.